#include "luminancecontroller.h"

LuminanceController::LuminanceController(QWidget *parent)
{
    luminanceView= new LuminanceView(parent);
    closeView();
    //绑定按钮信号
    connect(luminanceView,&LuminanceView::clickBtnIndex,this,&LuminanceController::menuClickBtnIndex);

    connect(luminanceView->closebtn,SIGNAL(clicked()),this,SLOT(closeView()));
    connect(luminanceView->verifybtn,SIGNAL(clicked()),this,SLOT(verifybtn()));



    isAutoLuminance = true;
    luminanceNum = 10;
    setNumLuminanceText();

    connect(luminanceView->autobtn,&QPushButton::clicked,[=]{
        isAutoLuminance = !isAutoLuminance;
        setNumLuminanceText();
    });
}

void LuminanceController::setNumLuminanceText()
{
    luminanceView->autobtn->setText(isAutoLuminance?"自动":"手动");
    luminanceView->numberLabel->setText(isAutoLuminance ? "AUTO":QString::number(luminanceNum));
}

LuminanceController::~LuminanceController()
{

}

void LuminanceController::show()
{
    luminanceView-> setGeometry(0,0,luminanceView->width() ==0 ?384:0,luminanceView->height()==0?558:0);
}

void LuminanceController::menuClickBtnIndex(int index)
{
    if(isAutoLuminance) return;
    if(index == 0){
        luminanceNum =luminanceNum<=10? 10:--luminanceNum;
    }else if(index == 1){
        luminanceNum =(luminanceNum >= 100) ? 100:++luminanceNum;

    }

    luminanceView->numberLabel->setText(QString::number(luminanceNum));

}

void LuminanceController::closeView()
{
    luminanceView-> setGeometry(0,0,0,0);
}

void LuminanceController::verifybtn()
{
    qDebug() << "点击确定";
}


